<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: easyui-header('用户列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
	<style type="text/css">
		.table .check-box, .radio-box {
			padding-left: 0;
		}
	</style>
</head>
<body class="white-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 组织机构
				</div>
				<div class="box-tools pull-right">
				    <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i class="fa fa-edit"></i></a>
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree3" class="ztree"></div>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-head">
					<div class="easyui-panel">
						<form id="user-form">
							<input type="hidden" id="deptId3" name="deptId">
			                <input type="hidden" id="parentId" name="parentId">
							<div class="select-list">
								<ul>
									<li>
										<label>登录名称：</label>
										<input type="text" name="loginName" class="easyui-textbox" data-options="prompt:'请输入登录名称'"/>
									</li>
									<li>
										<label>手机号码：</label>
										<input type="text" name="phonenumber" class="easyui-textbox" data-options="prompt:'请输入手机号码'"/>
									</li>
									<li>
										<label>用户状态：</label>
										<select name="status" class="easyui-combobox" th:with="type=${@dict.getType('sys_normal_disable')}">
											<option value=" ">所有</option>
											<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
										</select>
									</li>
									<li>
										<label>创建时间： </label>
										<input type="text" id="startTime" class="easyui-datebox" style="width: 110px;" data-options="prompt:'开始时间'" name="params[beginTime]"/>
										<span>-</span>
										<input type="text" id="endTime" class="easyui-datebox" style="width: 110px;" data-options="prompt:'结束时间'" name="params[endTime]"/>
									</li>
									<li>
										<a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="$.easyUIDataGrid.search()" >查询</a>
										<a class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="$.easyUIDataGrid.reset()" >重置</a>
									</li>
								</ul>
							</div>
						</form>
					</div>
				</div>
				<div class="col-sm-12 search-body">
			    	<div id="toolbar" role="group">
			            <a class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="$.easyUIOperate.add('850','480')" shiro:hasPermission="system:user:add">新增</a>
			            <a class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="$.easyUIOperate.edit('850','480')" shiro:hasPermission="system:user:edit">修改</a>
			            <a class="easyui-linkbutton" data-options="iconCls:'icon-delete'" onclick="$.easyUIOperate.removeAll()" shiro:hasPermission="system:user:remove">删除</a>
			            <a class="easyui-linkbutton" data-options="iconCls:'icon-import'" onclick="$.easyUIOperate.importExcel()" shiro:hasPermission="system:user:import">导入</a>
			            <a class="easyui-linkbutton" data-options="iconCls:'icon-export'" onclick="$.easyUIOperate.exportExcel()" shiro:hasPermission="system:user:export">导出</a>
			        </div>
				    <table id="dg" class="easyui-datagrid"></table>
				</div>
			</div>
		</div>
	</div>
	<th:block th:include="include :: easyui-footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
 	<script th:inline="javascript">
	 	var editFlag = [[${@permission.hasPermi('system:user:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
		var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
    </script>
	<script th:inline="none">
		var prefix = ctx + "system/user";
		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 235 });
	     	// 回到顶部绑定
	    	if ($.fn.toTop !== undefined) {
	    		var opt = {
	    			win:$('.ui-layout-center'),
	    			doc:$('.ui-layout-center')
	    		};
	    		$('#scroll-up').toTop(opt);
	    	}
		    queryUserList();
		    queryDeptTree();
		});

		function queryUserList() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        importUrl: prefix + "/importData",
		        importTemplateUrl: prefix + "/importTemplate",
		        idField: 'userId',
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "用户",
		        columns: [[
					{
						field:'ck',
						checkbox:true,
						width:30
					},
			        {
			            field: 'userId',
			            title: '用户ID',
		            	align: 'center',
		            	hidden:true,
						width: 20
			        },
			        {
			            field: 'loginName',
			            title: '登录名称',
			            sortable: true,
			            align: 'center',
			            width: 70
			        },
			        {
			            field: 'userName',
			            title: '用户名称',
			            align: 'center',
			            width: 60
			        },
			        {
			            field: 'userDeptName',
			            title: '部门',
			            align: 'center',
			            width: 80
			        },
			        {
			            field: 'phonenumber',
			            title: '手机',
			            align: 'center',
			            width: 60
			        },
			        {
			        	field: 'status',
			        	title: '用户状态',
			        	align: 'center',
			        	width: 60,
			        	formatter: function (value, row, index) {
			        		return statusTools(row);
			        	}
			        },
			        {
			            field: 'createTime',
			            title: '创建时间',
			            sortable: true,
			            align: 'center',
		          		width: 100
			        },
			        {
			        	field:'action',
			            title: '操作',
			            align: 'center',
			            width: 120,
			            formatter: function(value, row, index) {
			                var actions = [];
			                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.easyUIOperate.edit(\'850\',\'450\',\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
			                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.easyUIOperate.remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
			                actions.push("<a class='btn btn-info btn-xs " + resetPwdFlag + "' href='javascript:void(0)' onclick='resetPwd(" + row.userId + ")'><i class='fa fa-key'></i>重置密码</a> ");
			                return actions.join('');
			            }
			        }
		    	]],
		        onLoadSuccess: function(data){
		        	$(this).datagrid('doCellTip', { 'max-width': '700px', 'delay': 300 });
		        	if(editFlag == "" ? true : false){
		        		$(this).datagrid('showColumn', 'status');//列的field值
		        	} else {
		        		$(this).datagrid('hideColumn', 'status');//列的field值
		        	}
		        }
		    };
		    $.easyUIDataGrid.init(options);
		}
		
		function queryDeptTree(){
			var url = ctx + "system/dept/treeData";
			var options = {
				id: "tree3",
		        url: url,
		        expandLevel: 2,
		        onClick : zOnClick
		    };
			$.tree.init(options);
			
			function zOnClick(event, treeId, treeNode) {
				$("#deptId3").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
				$.easyUIDataGrid.search();
			}
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryDeptTree();
		});

		/* 用户管理-部门 */
		function dept() {
			var url = ctx + "system/dept";
			$.modal.openTab("部门管理", url);
		}

		/* 用户管理-重置密码 */
		function resetPwd(userId) {
		    var url = prefix + '/resetPwd/' + userId;
		    $.easyUIModal.open("重置密码", "icon-lock-break", "resetPwdDialog", url, '500', '250');
		}
		
		/* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
    		}
		}
		
		/* 用户管理-停用 */
		function disable(userId) {
			$.messager.confirm("确认", "确认要停用用户吗？", function (isDelete) {
 	        	if (isDelete) {
 	        		$.easyUIOperate.post(prefix + "/changeStatus", { "userId": userId, "status": 1 });
 	        	}
 	        });
		}

		/* 用户管理启用 */
		function enable(userId) {
			$.messager.confirm("确认", "确认要启用用户吗？", function (isDelete) {
 	        	if (isDelete) {
 	        		$.easyUIOperate.post(prefix + "/changeStatus", { "userId": userId, "status": 0 });
 	        	}
 	        });
		}
	</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>
		<div class="mt10 pt5">
			<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
			 &nbsp;	<a onclick="$.easyUIOperate.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
		</div>
		<font color="red" class="pull-left mt10">
			提示：仅允许导入“xls”或“xlsx”格式文件！
		</font>
	</div>
</form>
</script>
</html>